﻿namespace WMS6.Web.Inventory
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.InventoryMgtServiceRef;

    public class LPN : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnRefresh;
        protected Button btnSave;
        protected CheckBox chkIsActive;
        protected HtmlForm F5077;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnLpnID;
        protected HtmlHead Head1;
        protected HtmlInputHidden hidCheck;
        protected Label lblDescr;
        protected Label lblDocID;
        protected Label lblDocType;
        protected Label lblExpireDate;
        protected Label lblExternalLot;
        protected Label lblLotAttr01;
        protected Label lblLotAttr02;
        protected Label lblLotAttr03;
        protected Label lblLotAttr04;
        protected Label lblLotAttr05;
        protected Label lblLotAttr06;
        protected Label lblLotAttr07;
        protected Label lblLotAttr08;
        protected Label lblLotAttr09;
        protected Label lblLotAttr10;
        protected Label lblLpn;
        protected Label lblLpnID;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblPackID;
        protected Label lblProduceDate;
        protected Label lblQty;
        protected Label lblReceiptDate;
        protected Label lblSkuID;
        protected Label lblStatus;
        protected Label lblVendorID;
        protected LinkButton lnkbtnPrintLpnLabel;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnPrintLpnLabel;
        protected TextBox txtDescr;
        protected TextBox txtDocID;
        protected TextBox txtDocType;
        protected TextBox txtExpireDate;
        protected TextBox txtExternalLot;
        protected TextBox txtLotAttr01;
        protected TextBox txtLotAttr02;
        protected TextBox txtLotAttr03;
        protected TextBox txtLotAttr04;
        protected TextBox txtLotAttr05;
        protected TextBox txtLotAttr06;
        protected TextBox txtLotAttr07;
        protected TextBox txtLotAttr08;
        protected TextBox txtLotAttr09;
        protected TextBox txtLotAttr10;
        protected TextBox txtLpnID;
        protected TextBox txtOwnerID;
        protected TextBox txtPackID;
        protected TextBox txtProduceDate;
        protected TextBox txtQty;
        protected TextBox txtReceiptDate;
        protected TextBox txtSkuID;
        protected TextBox txtStatus;
        protected TextBox txtVendorID;

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtQty.Text) || (decimal.Parse(this.txtQty.Text) == 0M))
                {
                    List<string> selectedID = new List<string> {
                        this.txtLpnID.Text
                    };
                    this.lblMsg.Text = InventoryMgtServiceClientProxy.GetInstance().DeleteLpn(selectedID) + base.GetGlobalMsgResource("F4100_012");
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                }
                else
                {
                    this.lblMsg.Text = "lpn数量大于0无法删除！";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_013") + ex.Message;
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("LPNQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("LPNList.aspx?from=edit", false);
                    break;
            }
        }

        protected void lnkbtnPrintLpnLabel_Click(object sender, EventArgs e)
        {
            this.Session["PrintLpnIDS"] = "'" + this.txtLpnID.Text + "'";
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>popPrinLpnLabel();</script>", false);
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnLpnID.Value = base.Request.QueryString["ID"].ToString();
                this.SetAreaInfo2Form();
                this.hdnFlag.Value = "1";
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetAreaInfo2Form()
        {
            try
            {
                string lpnID = this.hdnLpnID.Value;
                LpnInfo lpnInfo = InventoryMgtServiceClientProxy.GetInstance().GetLpnByID(lpnID);
                base.DataEntityViewState = lpnInfo;
                if (lpnInfo != null)
                {
                    this.txtLpnID.Text = lpnInfo.LpnID;
                    this.txtStatus.Text = lpnInfo.Status;
                    this.txtPackID.Text = lpnInfo.PackID;
                    this.txtQty.Text = base.GetPreferenceDigit(lpnInfo.Qty);
                    this.txtDocID.Text = lpnInfo.DocID;
                    this.txtDocType.Text = lpnInfo.DocType;
                    this.chkIsActive.Checked = lpnInfo.IsActive == "Y";
                }
                InventoryInfo inventoryInfo = InventoryMgtServiceClientProxy.GetInstance().GetInventoryInfoByLpnID(lpnID);
                if (inventoryInfo != null)
                {
                    this.txtOwnerID.Text = inventoryInfo.OwnerID;
                    this.txtSkuID.Text = inventoryInfo.SkuID;
                    this.txtDescr.Text = inventoryInfo.SkuDescr;
                    this.txtLotAttr01.Text = inventoryInfo.LotAttr01;
                    this.txtLotAttr02.Text = inventoryInfo.LotAttr02;
                    this.txtLotAttr03.Text = inventoryInfo.LotAttr03;
                    this.txtLotAttr04.Text = inventoryInfo.LotAttr04;
                    this.txtLotAttr05.Text = inventoryInfo.LotAttr05;
                    this.txtLotAttr06.Text = inventoryInfo.LotAttr06;
                    this.txtLotAttr07.Text = inventoryInfo.LotAttr07;
                    this.txtLotAttr08.Text = inventoryInfo.LotAttr08;
                    this.txtLotAttr09.Text = inventoryInfo.LotAttr09;
                    this.txtLotAttr10.Text = inventoryInfo.LotAttr10;
                    this.txtProduceDate.Text = base.GetPreferenceShortDate(inventoryInfo.ProduceDate);
                    this.txtExpireDate.Text = base.GetPreferenceShortDate(inventoryInfo.ExpiryDate);
                    this.txtExternalLot.Text = inventoryInfo.ExternalLot;
                    this.txtReceiptDate.Text = base.GetPreferenceShortDate(inventoryInfo.ReceiptDate);
                    this.txtVendorID.Text = inventoryInfo.VendorID;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }
    }
}

